{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 对常用切片命名可以提高代码的可读性和可维护性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20 23 1\n",
      "100 513.32\n"
     ]
    }
   ],
   "source": [
    "record = '********************100*********513.32'\n",
    "PRICE = slice(20, 23, 1)\n",
    "print(PRICE.start, PRICE.stop, PRICE.step)\n",
    "RATE = slice(32, 38, 1)\n",
    "print(record[PRICE], record[RATE])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 使用``indices()``笔辩IndexError错误"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "World"
     ]
    }
   ],
   "source": [
    "s = 'HelloWorld'\n",
    "a = slice(5, 20, 1)\n",
    "for i in range(*a.indices(len(s))):\n",
    "    print(s[i], end='')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.4 64-bit",
   "language": "python",
   "name": "python37464bit0eab7a6caf29454899b876d50238c56e"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
